<?php
namespace Home\Model;
use Think\Model;

class CommonModel extends Model{

 	// 检测输入的验证码是否正确，$code为用户输入的验证码字符串
    public function check_verify($code, $id = '')
    {
	    $verify = new \Think\Verify();
	    return $verify->check($code, $id);

	}

	//发送短信验证码
	public function sendSMS($tel,$code)
	{
		
	$ch = curl_init();
    $url = "http://apis.baidu.com/kingtto_media/106sms/106sms?mobile={$tel}&content=【KBBS论坛】，您的验证码为{$code}，请在5分钟内输入。";
    $header = array(
        'apikey: de4c75243c4026b380235537302907d8',
    );
    // 添加apikey到header
    curl_setopt($ch, CURLOPT_HTTPHEADER  , $header);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    // 执行HTTP请求
    curl_setopt($ch , CURLOPT_URL , $url);
    $res = curl_exec($ch);
    $status = json_decode($res);
    if($status->errNum){
    	return false;
    }else{
    	return true;
    }


	}

	//验证短信验证码
	public function checkSMS($code)
	{
		$sms_code = session('sms_code'); 
		if($code == $sms_code){
			return true;
		}else{
			return false;
		}
	}
}